home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import dns
- import dns.resolver as dns
- import dns.exception as dns
- import spf
- spf.RESULTS = {
- '+': 'pass',
- '-': 'deny',
- '?': 'unknown',
- '~': 'softfail',
- 'pass': 'pass',
- 'deny': 'deny',
- 'unknown': 'unknown' }
- spf.EXPLANATIONS = {
- 'pass': 'sender SPF verified',
- 'deny': 'access denied',
- 'unknown': 'SPF unknown',
- 'softfail': 'sender SPF not verified' }
-
- def check(i, s, h):
- if i.startswith('127.'):
- return ('pass', 250, 'local connections always pass')
-
-
- try:
- q = spf_query(i = i, s = s, h = h)
- return q.check(q.dns_spf(q.d))
- except dns.exception.DNSException:
- return ('error', 450, 'SPF DNS Error')
-
-
-
- class spf_query(spf.query):
-
- def validated_ptrs(self, i):
- '''Figure out the validated PTR domain names for a given IP
- \t\taddress.
- \t\t'''
- return _[1]
-
-
- def dns_a(self, domainname):
- raw = spf.query.dns_a(self, domainname)
- return [ str(a) for a in raw ]
-
-
- def dns_mx(self, domainname):
- '''Get a list of IP addresses for all MX exchanges for a
- \t\tdomain name.
- \t\t'''
- return [ str(a) for mx in self.dns(domainname, 'MX') for a in self.dns_a(str(mx.exchange)) ]
-
-
- def dns_txt(self, domainname):
- result = []
- for a in self.dns(domainname, 'TXT'):
- if hasattr(a, 'strings'):
- []([ t for t in a.strings ])
- continue
- []
-
- return result
-
-
- def dns(self, name, qtype):
- """DNS query.
-
- \t\tIf the result is in cache, return that. Otherwise pull the
- \t\tresult from DNS, and cache ALL answers, so additional info
- \t\tis available for further queries later.
-
- \t\tCNAMEs are followed.
-
- \t\tIf there is no data, [] is returned.
-
- \t\tpre: qtype in ['A', 'AAAA', 'MX', 'PTR', 'TXT', 'SPF']
- \t\tpost: isinstance(__return__, types.ListType)
- \t\t"""
- result = self.cache.get((name, qtype))
- cname = None
- if not result:
- answers = dns.resolver.query(name, qtype)
- for a in answers.response.answer:
- k = (name, qtype)
- v = a.items
- for part in v:
- if part.rdtype == 5:
- cname = str(part.target)
- break
- continue
-
-
- result = self.cache.get((name, qtype), [])
-
- if not result and cname:
- result = self.dns(cname, qtype)
-
- return result
-
-
-